<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function request1() {
        console.log(1);
      }
      function request2() {
        throw new Error("cuowu");
      }
      function request3() {
        console.log(3);
      }
      let arr = [request1, request2, request3];

      function list(list) {
        list.reduce((promise, task, index) => {
          return (promise = promise.then(
            (value) => {
              return new Promise((resolve, reject) => {
                try {
                  task();
                  resolve();
                } catch (error) {
                  console.log(error);
                  //执行三次
                  for (let index = 0; index < 3; index++) {
                    task();
                    console.log(index);
                  }
                  reject(error);
                }
              });
            },
            (reson) => {
              console.log(reson);
            }
          ));
        }, Promise.resolve());
      }

      list(arr);

      // let a = new Promise((resolve, reject) => {
      //   try {
      //     throw new Error("牛逼");
      //     resolve();
      //   } catch (error) {
      //     reject(error);
      //   }
      // })
      //   .then(
      //     (value) => {},
      //     (reson) => {
      //       console.log(reson);
      //       return 1;
      //     }
      //   )
      //   .then((value) => {
      //     console.log(value);
      //   });
    </script>
  </body>
</html>
